﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZXing; 
using ZXing.QrCode;

namespace PIMS.QRCODE
{
    public static class ZxingQRCode
    {
        /// <summary>
        /// 生成二维码,保存成图片
        /// net4.5
        /// </summary>
        public static Bitmap GenerateQRCode(string text, int width = 500, int height = 500)
        {
            BarcodeWriter writer = new BarcodeWriter();
            writer.Format = BarcodeFormat.QR_CODE;
            QrCodeEncodingOptions options = new QrCodeEncodingOptions();
            options.DisableECI = true;
            //设置内容编码
            options.CharacterSet = "UTF-8";
            //设置二维码的宽度和高度
            options.Width = width;
            options.Height = height;
            //设置二维码的边距,单位不是固定像素
            options.Margin = 1;
            writer.Options = options;

            Bitmap map = writer.Write(text);
            return map;
        }
    }
}
